import requests
import execjs

with open('DecryptCode.js',mode='r',encoding='utf-8') as file:
    jsFile = file.read()
ctx = execjs.compile(jsFile)

pubKey = '9bf389c15ad7435a'

headers = {
    'authority': 'capi.coinglass.com',
    'accept': 'application/json',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'cache-ts': '1726464919621',
    'encryption': 'true',
    'language': 'zh',
    'origin': 'https://www.coinglass.com',
    'referer': 'https://www.coinglass.com/',
    'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0',
}

params = {
    'sort': '',
    'order': '',
    'keyword': '',
    'pageNum': '1',
    'pageSize': '20',
    'ex': 'all',
}

response = requests.get(
    'https://capi.coinglass.com/api/home/v2/coinMarkets',
    params=params,
    headers=headers
)
# print(response)
json_data = response.json()
data = json_data['data']
# print(data)
DecryptRes = ctx.call('getData',data,pubKey)
print(DecryptRes)